import java.util.*;

public class Test {
    public static void main(String[] args) {
        Set<String> set = new TreeSet<>();
        set.add("abc");
        set.add("uihrge");
        set.add("nfuhr");//TreeSet的底层是TreeMap，每次存储元素放到Map的key上，所以Set中的元素不能重复
        set.add("abc");//set中只能存放key,且不能重复。
//        set.clear();
        //迭代器用来遍历元素
        Iterator<String> it = set.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }
    }
    public static void main1(String[] args) {
        Map<String, Integer> map = new TreeMap<>();//接口接收其类的实例化对象
        map.put("abc", 2);
        map.put("abcd", 5);
        map.put("sadef", 1);
        map.put("cdfe", 45);
        map.put("ffwa", 24);
        map.put("ffhq", 10);//按照key的值进行比较排序
        int value = map.getOrDefault("adf",9999);
        System.out.println(value);
        Set<String> set = map.keySet();
        Collection<Integer> set1 = map.values();
        for (String s:set) {
            System.out.print(s + " ");
        }
        System.out.println();
        for (int i:set1) {
            System.out.print(i + " ");
        }
        System.out.println();

        Set<Map.Entry<String,Integer>> entrySet = map.entrySet();
        for (Map.Entry<String,Integer> entry: entrySet) {
            System.out.print("key:" + entry.getKey() + " value:" + entry.getValue());
            System.out.println();
        }
        System.out.println();

    }
}
